package com.bonc.common.utils;

import org.apache.http.HttpStatus;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 返回数据
 */
public class ReplyCommon extends LinkedHashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public ReplyCommon() {

    }

    public static ReplyCommon error() {
        return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常，请联系管理员");
    }

    public static ReplyCommon error(String msg) {
        return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
    }

    public static ReplyCommon error(int code, String msg) {
        ReplyCommon r = new ReplyCommon();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public static ReplyCommon error(String rspCode, String rspDesc) {
        ReplyCommon r = new ReplyCommon();
        Map renturnMap = new HashMap();
        renturnMap.put("rspCode",rspCode);
        renturnMap.put("rspDesc",rspDesc);
        r.put("response", renturnMap);
        return r;
    }

    public static ReplyCommon ok(String msg) {
        ReplyCommon r = new ReplyCommon();
        r.put("msg", msg);
        return r;
    }

    public static ReplyCommon ok(String transIDO, String cutOffDay,String providePartyID, String rspCode, String rspDesc) {
        ReplyCommon r = new ReplyCommon();
        Map renturnMap = new HashMap();
        renturnMap.put("rspCode",rspCode);
        renturnMap.put("rspDesc",rspDesc);
        r.put("transIDO", transIDO);
        r.put("cutOffDay", cutOffDay);
        r.put("providePartyID", providePartyID);
        r.put("response", renturnMap);
        return r;
    }

    public static ReplyCommon ok(String transIDO, String cutOffDay,String transIDH, String transIDHTime,String providePartyID, String rspCode, String rspDesc) {
        ReplyCommon r = new ReplyCommon();
        Map renturnMap = new HashMap();
        renturnMap.put("rspCode",rspCode);
        renturnMap.put("rspDesc",rspDesc);
        r.put("transIDH", transIDH);
        r.put("transIDHTime", transIDHTime);
        r.put("transIDO", transIDO);
        r.put("cutOffDay", cutOffDay);
        r.put("providePartyID", providePartyID);
        r.put("response", renturnMap);
        return r;
    }

    public static ReplyCommon ok(Map<String, Object> map) {
        ReplyCommon r = new ReplyCommon();
        r.putAll(map);
        return r;
    }

    public static ReplyCommon ok() {
        return new ReplyCommon();
    }

    public static ReplyCommon instance(boolean res) {
        return res ? new ReplyCommon() : error();
    }

    @Override
    public ReplyCommon put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
